package odl;

import java.util.Vector;

public class Relation extends OdlElement {
	
	private String target_name;
	private String target_type;
	private String inverse_interface;
	private String inverse_relation;
	private Interface targeted_interface;
	private Relation inversed_relation;
	private Boolean key;
	
	/**
	 * @return the key
	 */
	public Boolean getKey() {
		return key;
	}


	/**
	 * @param key the key to set
	 */
	public void setKey(Boolean key) {
		this.key = key;
	}


	public boolean equals(Relation r){
		return this.target_name.equals(r.getTarget_name())
				&& this.target_type.equals(r.getTarget_type())
				&& this.inverse_interface.equals(r.getInverse_interface())
				&& this.inversed_relation.equals(r.getInversed_relation());
	}
	

	/**
	 * @return the target_name
	 */
	public String getTarget_name() {
		return target_name;
	}


	/**
	 * @return the target_type
	 */
	public String getTarget_type() {
		return target_type;
	}


	/**
	 * @return the inverse_interface
	 */
	public String getInverse_interface() {
		return inverse_interface;
	}


	/**
	 * @return the inverse_relation
	 */
	public String getInverse_relation() {
		return inverse_relation;
	}


	/**
	 * @return the targeted_interface
	 */
	public Interface getTargeted_interface() {
		return targeted_interface;
	}


	/**
	 * @return the inversed_relation
	 */
	public Relation getInversed_relation() {
		return inversed_relation;
	}


	public Relation(){
		super();
		target_type = null;
	}
	
	public Relation(String _name) {
		super(_name);
		target_type="";
		// TODO Auto-generated constructor stub
	}
	
	public void addInverseInterface(String _s){
		inverse_interface = _s;
	}
	
	public void addInverseRelation(String _s){
		inverse_relation = _s;
	}
	
	public void addName(String _name){
		set_name(_name);
	}
	
	public void addTargetName(String _name){
		target_name = _name;
		
	}
	
	public void addTargetType(String _type){
		target_type = _type;
	}
	
	public Vector<String> getDetails(){
		Vector<String> v = new Vector<String>();
		v.add("Target name : "+target_name);
		v.add("Target type : "+target_type);
		v.add("Related interface : "+inverse_interface);
		v.add("Related interface's relation : "+inverse_relation);
		return v;
	}
	
	public void updateContent(Boolean iskey){
		targeted_interface = Controller.getController().get_Schema().getInterface(inverse_interface);
		inversed_relation = targeted_interface.getRelation(inverse_relation);
		key = iskey;
	}
	
}
